class MemorylanesController < ApplicationController
  def index

     @memorylanes = Memorylane.find_all_by_user_id(@facebook_user.uid).paginate(:page => params[:page],:per_page =>10)
     logger.info("THE memorylane COUNT is:" + @memorylanes.size.to_s)
         respond_to do |format|
           format.html  { render :layout => 'memorylanes.html'}
           format.fbml { render :layout => 'memorylanes.fbml'}
         end
   end


  def home
  #  @template.url_for({:controller => 'memorylanes', :action => 'home'})
    @memorylanes = Memorylane.find_all_by_user_id(@facebook_user.uid).paginate(:page => params[:page],:per_page =>10)
   # logger.info("THE memorylane path is is:" + @template.url_for(:controller => 'memorylanes', :action => 'home',:path_only => false))
         respond_to do |format|
           format.html  { render :layout => 'memorylanes.html'}
           format.fbml { render :layout => 'memorylanes.fbml'}
         end

  end

  def new
      @memorylane = Memorylane.new
      @timeline_plugin_registers = TimelinePluginRegister.all.paginate(:page => params[:page],:per_page =>3)
    respond_to do |format|

      format.html  { render :layout => 'memorylanes.html'}
      format.fbml { render :layout => 'memorylanes.fbml'}
    end
  end


  def newfrm
    @memorylane = Memorylane.new
    @friends=get_user.friends
    @memorylane.timeline_plugin_register_id = params[:id]
   
    respond_to do |format|

      format.html  { render :layout => 'memorylanes.html'}
      format.fbml { render :layout => 'memorylanes.fbml'}
    end
  end

  def create

    @memorylane = Memorylane.new(params[:memorylane])
    if @memorylane.access_to_all_friends
      logger.info("the friends are"+params[:fb_sig_friends])
      @memorylane.allowed_friend_ids = params[:fb_sig_friends]
    else
      @memorylane.allowed_friend_ids = params[:ids]
    end
    @timeline_plugin_register = TimelinePluginRegister.find(@memorylane.timeline_plugin_register_id)

    @memorylane.timeline_js = @timeline_plugin_register.timeline_js
 # to do   if @timeline_plugin_register.url_list.nil
    
#    else

 #   end
    @memorylane.user_id = get_user().uid
    
    respond_to do |format|
      if @memorylane.save
        flash[:notice] = 'Your memorylane was successfully created.'
        format.html { redirect_to(@memorylane) }
        format.fbml {render :action => "show"}
        format.xml  { render :xml => @memorylane, :status => :created, :location => @memorylane }
      else
        logger.info(@memorylane.errors)
        format.html { render :action => "newfrm" }
        format.fbml { render :action => "newfrm" }
        format.xml  { render :xml => @memorylane.errors, :status => :unprocessable_entity }
      end
    end
    end


  def show

   @memorylane_id=params[:id]
 #  logger.info("THE memorylane timeline  path is is:" + @template.url_for(:canvas=> false,:action => 'show_timeline', :controller => 'memorylane', :only_path => false, :id => @memorylane_id))
   respond_to do |format|
        format.fbml { render :layout => 'memorylanes.fbml'}
     end

  end

  def show_timeline
     
    @memorylane = Memorylane.find(params[:id])

   respond_to do |format|
    
     format.html {render :layout => false}
     
    end

  end

  def delete
     @memorylane = Memorylane.find(params[:id])


   respond_to do |format|
    if @memorylane.destroy
      flash[:notice] = 'Your memorylane was successfully deleted.'
     format.fbml { redirect_to :back }
     else
      flash[:notice] = 'We were unable to delete Your memorylane'
     format.fbml { redirect_to :back }
     end
      

    end

  end

  def edit
    @memorylane = Memorylane.find(params[:id])
    @friends=get_user.friends
    @memorylane.timeline_plugin_register_id = params[:id]

    respond_to do |format|

      format.html  { render :layout => 'memorylanes.html'}
      format.fbml { render :layout => 'memorylanes.fbml'}
    end
  end

  def createfrmconfig
  end

end
